﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;

namespace Silverlight.Arcgis.MapTip.DataEntity
{
    /// <summary>
    /// 对像集合管理类
    /// </summary>
    public class ObjectListManager<T> : System.ComponentModel.INotifyPropertyChanged
    {
        /// <summary>
        /// 对像集合
        /// </summary>
        private List<T> listObject = new List<T>();


        #region 公共属性
        public List<T> Source
        {
            get
            {
                return listObject;
            }
            set
            {
                listObject = value;
                //属性改变事件
                RegPropertyChanged("Source");
            }
        }
        #endregion



        /// <summary>
        /// 得到值的索引器
        /// </summary>
        /// <param name="index">得到指定位置的对像</param>
        /// <returns>类型</returns>
        public T this[int index]
        {
            get
            {

                return listObject[index];

            }
        }

        #region 共开的方法
        /// <summary>
        /// 添加 新项
        /// </summary>
        /// <param name="item">新项</param>
        public void Add(T item)
        {
            listObject.Add(item);

            //属性改变事件
            RegPropertyChanged("Source");
        }

        /// <summary>
        /// 移除对像
        /// </summary>
        /// <param name="item"></param>
        public void Remove(T item)
        {
            listObject.Remove(item);
            //属性改变事件
            RegPropertyChanged("Source");
        }

        /// <summary>
        /// 删除对像
        /// </summary>
        /// <param name="index">对像索引</param>
        public void RemoveAt(int index)
        {
            listObject.RemoveAt(index);

            //属性改变事件
            RegPropertyChanged("Source");
        }
        #endregion

        #region INotifyPropertyChanged 成员

        /// <summary>
        /// 属性改变的事件
        /// </summary>
        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// 注册属性值改变事件
        /// </summary>
        /// <param name="PropertyName">属性名</param>
        private void RegPropertyChanged(string PropertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(PropertyName));
            }
        }
        #endregion

    }
}


